package com.github.common.exception;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.github.common.utils.StringUtils;

/**
 * <p>User: Mu Yunlong
 * <p>Date: 2016年3月3日 下午4:35:54
 * <p>Version: 1.0
 */
public class ExceptionCode {
    public static final String CODE_0000 = "0000";
    public static final String MSG_0000 = "网络异常！!";
    public static final String CODE_1000 = "1000";
    public static final String MSG_1000 = "数据操作异常!";
    public static final String CODE_1001 = "1001";
    public static final String MSG_1001 = "字段已存在!";
    public static final String CODE_2000 = "2000";
    public static final String MSG_2000 = "文件操作异常!";
    public static final String CODE_9999 = "9999";
    public static final String MSG_9999 = "其它错误!";
    private static Map<String, String> returnCodeMap = new ConcurrentHashMap<>();

    static
    {
      returnCodeMap.put("0000", "网络异常！!");

      returnCodeMap.put("1000", "数据操作异常!");
      returnCodeMap.put("1001", "字段已存在!");

      returnCodeMap.put("2000", "文件操作异常!");

      returnCodeMap.put("9999", "其它错误!");
    }

    private ExceptionCode()
    {
      throw new Error("工具类不能实例化");
    }

    public static String getMsgByCode(String code)
    {
      if (StringUtils.isEmpty(code)) {
        return "网络异常！!";
      }
      String msg = (String)returnCodeMap.get(code);
      if (msg == null) {
        msg = code;
      }
      return msg;
    }
}
